import {defineStore} from "pinia";
import {ref} from "vue";


export const useUserStore = defineStore('user', () => {
    const updateCurrentAddress=(userInfo)=>{
        userList.value.find(item=>item.id===currentUserInfo.value.id).currentAddress=userInfo
    }
    const addUser=(userInfo)=>{
            userList.value.find(item=>item.id===currentUserInfo.value.id).addressList.push(userInfo)

    }
    const currentUserInfo = ref(null);
    const userList = ref([
        {
            name: 'zhangsan',
            password: '123',
            id: '000001',
            imgUrl: 'http://www.dell-lee.com/imgs/vue3/orange.png',
            list: [
                {title: '红包', content: 218},
                {title: '优惠劵', content: '12张'},
                {title: '红豆', content: 88},
                {title: '白条', content: 1000}
            ],
            addressList: [
                {
                    name: '小慕',
                    phone: 18611111111,
                    address_text: '北京 海淀区西三环北路2号院北京理工大学国防科技园2号楼10号'
                },
                {
                    name: '小可',
                    phone: 18622222222,
                    address_text: '北京 朝阳区北京工业大学3号楼303'
                }
            ],
            currentAddress: null
        },
        {
            name: 'admin',
            password: '123',
            id: '000002',
            imgUrl: 'http://www.dell-lee.com/imgs/vue3/orange.png',
            list: [
                {title: '红包', content: 22},
                {title: '优惠劵', content: '7张'},
                {title: '红豆', content: 120},
                {title: '白条', content: 2000}
            ],
            addressList: [],
            currentAddress: null
        }
    ]);


    return {userList,currentUserInfo,addUser,updateCurrentAddress}
});

